package com.ymatou.iapi.m.couponservice.testcase;

import java.util.Calendar;
import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.m.couponservice.parameter.GetBatchCountBean;
import com.ymatou.iapi.m.couponservice.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.m.couponservice.service.GetBatchCountCall;
import com.ymatou.iapi.m.couponservice.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallService;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取商家批次数量统计信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetBatchCount{
	private static GetBatchCountBean getbatchcountBean;
	private static GetBatchCountCall getbatchcountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商家批次数量统计信息");
	}

	@Before
	public void caseUp() {
		getbatchcountBean=new GetBatchCountBean();
		getbatchcountCall=new GetBatchCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbatchcountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBatchCount_001() {
		Logger.start(true,"获取商家批次数量统计信息");
		try {
			
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			getbatchcountBean.setSellerId(sellerId);
			
			getbatchcountCall.setData(getbatchcountBean);
			getbatchcountCall.callService();	
			
			Logger.verifyEquals("0", getbatchcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getbatchcountCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBatchCount_002() {
		Logger.start(true,"获取商家批次数量统计信息-领取中");
		try {
			
			CouponServiceMCallService couponServiceMCallService = new CouponServiceMCallService();
			SellerCreateBatchBean sellercreatebatchBean = couponServiceMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			
			getbatchcountBean.setSellerId(sellercreatebatchBean.getSellerId());
			
			getbatchcountCall.setData(getbatchcountBean);
			getbatchcountCall.callService();	
			
			Logger.verifyEquals("0", getbatchcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getbatchcountCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("0", getbatchcountCall.getExpireCount(), "验证返回expireCount");
			Logger.verifyEquals("2", getbatchcountCall.getReceivingCount(), "验证返回receivingCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceiveOverCount(), "验证返回receiveOverCount");
			Logger.verifyEquals("0", getbatchcountCall.getStopReceiveCount(), "验证返回stopReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBatchCount_003() {
		Logger.start(true,"获取商家批次数量统计信息-过期");
		try {
			
			CouponServiceMCallService couponServiceMCallService = new CouponServiceMCallService();
			SellerCreateBatchBean sellercreatebatchBean = couponServiceMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);

			YmtCouponBatch batch = new YmtCouponBatchWapper().selectBysBatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间
			
			new YmtCouponSettingWapper().setdValidEnd(batch.getiCouponSettingId(), dBefore);
			
			getbatchcountBean.setSellerId(sellercreatebatchBean.getSellerId());
			
			getbatchcountCall.setData(getbatchcountBean);
			getbatchcountCall.callService();	
			
			Logger.verifyEquals("0", getbatchcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getbatchcountCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("1", getbatchcountCall.getExpireCount(), "验证返回expireCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceivingCount(), "验证返回receivingCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceiveOverCount(), "验证返回receiveOverCount");
			Logger.verifyEquals("0", getbatchcountCall.getStopReceiveCount(), "验证返回stopReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBatchCount_004() {
		Logger.start(true,"获取商家批次数量统计信息-停止发放");
		try {
			
			CouponServiceMCallService couponServiceMCallService = new CouponServiceMCallService();
			SellerCreateBatchBean sellercreatebatchBean = couponServiceMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			
			couponServiceMCallService.InvalidSellerBatch(sellercreatebatchBean.getSellerId(), sellerCreateBatchCall.getBatchCode());
			
			getbatchcountBean.setSellerId(sellercreatebatchBean.getSellerId());
			
			getbatchcountCall.setData(getbatchcountBean);
			getbatchcountCall.callService();	
			
			Logger.verifyEquals("0", getbatchcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getbatchcountCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("0", getbatchcountCall.getExpireCount(), "验证返回expireCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceivingCount(), "验证返回receivingCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceiveOverCount(), "验证返回receiveOverCount");
			Logger.verifyEquals("1", getbatchcountCall.getStopReceiveCount(), "验证返回stopReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBatchCount_005() {
		Logger.start(true,"获取商家批次数量统计信息-已领完");
		try {
			
			CouponServiceMCallService couponServiceMCallService = new CouponServiceMCallService();
			SellerCreateBatchBean sellercreatebatchBean = couponServiceMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			
			YmtCouponBatch batch = new YmtCouponBatchWapper().selectBysBatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			new YmtCouponSettingWapper().setiReceiveCount(batch.getiCouponSettingId(), sellercreatebatchBean.getCouponTotalCount());
			
			getbatchcountBean.setSellerId(sellercreatebatchBean.getSellerId());
			
			getbatchcountCall.setData(getbatchcountBean);
			getbatchcountCall.callService();	
			
			Logger.verifyEquals("0", getbatchcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getbatchcountCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("0", getbatchcountCall.getExpireCount(), "验证返回expireCount");
			Logger.verifyEquals("0", getbatchcountCall.getReceivingCount(), "验证返回receivingCount");
			Logger.verifyEquals("1", getbatchcountCall.getReceiveOverCount(), "验证返回receiveOverCount");
			Logger.verifyEquals("0", getbatchcountCall.getStopReceiveCount(), "验证返回stopReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}